/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.tag;

import com.apt.bean.User;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

/**
 *
 * @author Lambach
 */
public class ShowUser extends TagSupport {

    private String page;
//    private static final Map<Integer, User> hm = Collections.synchronizedMap(new ConcurrentHashMap<Integer, User>());

    @Override
    public int doEndTag() throws JspException {
        JspWriter out = pageContext.getOut();
        int cursor1;
        String query = "select * from Accounts where Account_Status=1 and Account_Role!='admin'";
        HashMap<Integer, User> hm = GetUser.getListUser(query);
        try {
            if (hm != null && hm.size() != 0) {
                out.println(Process_Page.divPage(page, hm.size(), 1));
                int uid_f = 1;
                int uid_l = 30;

                try {
                    cursor1 = Integer.parseInt(page);

                } catch (NumberFormatException ex) {
                    cursor1 = 1;
                }
                if (cursor1 > 1) {
                    uid_f = (cursor1 - 1) * 30;
                    uid_l = cursor1 * 30;
                }
                
                int current_page=uid_l/30;
                
                for (int i = uid_f; i < uid_l; i++) {
                    User u = hm.get(i);
                    if (u != null) {
                       
                        StringBuilder sb = new StringBuilder(" <tr>");
                        //sb.append(" <td><input type='checkbox' /></td>");
                        sb.append("<td>" + u.getUser_Name() + "</td>");
                        sb.append("  <td><a href=\"#\" title=\"title\">" + u.getUser_Email() + "t</a></td>");
                        sb.append("   <td>" + u.getDate_Registed() + "</td>");
                        sb.append("   <td>" + u.getDate_Expired() + "</td>");
                        sb.append("    <td>");
                        sb.append("        <!-- Icons -->");
                        
                        sb.append("       <a href=\"Disable_User_Servlet?user_id=" + u.getAccount_Id() +"&pageno="+current_page+ "\" title=\"Disable\"><img src=\"resources/images/icons/cross.png\" alt=\"Disable\" /></a>");
                        sb.append("   </td>");
                        sb.append(" </tr>");

                        out.print(sb.toString());
                       
                    }
                }

            }


        } catch (IOException ex) {
            Logger.getLogger(ShowUser.class.getName()).log(Level.SEVERE, null, ex);
        }

        return EVAL_PAGE;
    }

    /**
     * @return the page
     */
    public String getPage() {
        return page;
    }

    /**
     * @param page the page to set
     */
    public void setPage(String page) {
        this.page = page;
    }
}
// sb.append("       <a href=\"Disable_User_Servlet?user_id=" + u.getAccount_Id() +"&pageno="+current_page+ "\" title=\"Disable\"><img src=\"resources/images/icons/cross.png\" alt=\"Disable\" /></a>");
//sb.append("        <a href=\"#\" title=\"Enable\"><img src=\"resources/images/icons/pencil.png\" alt=\"Enabale\" /></a>");
//sb.append("       <a href=\"#\" title=\"Edit Meta\"><img src=\"resources/images/icons/hammer_screwdriver.png\" alt=\"Edit Meta\" /></a>");sb.append("       <a href=\"#\" title=\"Edit Meta\"><img src=\"resources/images/icons/hammer_screwdriver.png\" alt=\"Edit Meta\" /></a>");
